package o;

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.pm.PackageInfo;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.huawei.appgallery.assistantdock.base.externalaction.openviewaction.RemoteBuoyAction;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appgallery.foundation.ui.framework.widget.button.DownloadButton;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appmarket.service.installdepend.bean.GetDetailByIdResBean;
import com.huawei.appmarket.service.installdepend.bean.GetDetailByIdResBean$DetailInfoBean;
import com.huawei.fastengine.fastview.FastSDKEngine;
import com.huawei.fastengine.fastview.startFastappEngine.bean.RpkInfo;
import com.huawei.hms.aaid.constant.AaidIdConstant;
import com.huawei.hwid.core.constants.HwAccountConstants;
import java.io.File;
import java.lang.ref.WeakReference;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import o.ewm.n;
import org.json.JSONException;
import org.json.JSONObject;

public class ear {
    private static Handler ˊ;
    private static WeakReference<djl> ˎ;
    private static boolean ˏ = false;

    static class a implements cfd {
        private String ˊ;
        private String ˋ;
        private int ˎ;
        private String ˏ;
        private Context ॱ;

        a(Context context, String str, String str2, int i, String str3) {
            this.ॱ = context;
            this.ˋ = str;
            this.ˏ = str2;
            this.ˊ = str3;
            this.ˎ = i;
        }

        public void ˋ(int i, int i2, List<cfe> list) {
            if (i2 != 0 || i != 0 || ear.ˏ) {
                evk.ॱ(this.ॱ.getResources().getString(n.ॱᐧ), 0).ˋ();
            } else if (list != null && list.size() > 0) {
                if (((cfe) list.get(0)).ˏ != 1) {
                    String ॱ = drj.ॱ(this.ˋ);
                    if (ear.ॱ(this.ˋ, this.ˎ)) {
                        ear.ˋ(ॱ, this.ॱ);
                    } else {
                        ear.ˊ(this.ˏ, this.ˋ, ॱ, 3, this.ॱ);
                    }
                } else if (TextUtils.isEmpty(this.ˊ)) {
                    ced.ˎ(this.ॱ, this.ˋ, this.ˏ);
                } else {
                    ear.ˎ(this.ˊ, this.ॱ);
                }
            }
            ear.ˊ.sendMessage(ear.ˊ.obtainMessage(2));
        }
    }

    public static class b {
        public RpkInfo ʻ;
        public String ʼ;
        public int ʽ;
        public int ˊ;
        public String ˋ;
        public String ˎ;
        public String ˏ;
        public String ॱ;
        public int ॱॱ;
    }

    static class d extends Handler {
        private d() {
        }

        public void handleMessage(@NonNull Message message) {
            super.handleMessage(message);
            if (message.what == 2) {
                ear.ˎ();
            }
        }
    }

    static class e implements IServerCallBack {
        private Context ˏ;
        private String ॱ;

        e(Context context, String str) {
            this.ˏ = context;
            this.ॱ = str;
        }

        public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
        }

        public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
            GetDetailByIdResBean getDetailByIdResBean = (GetDetailByIdResBean) responseBean;
            if (getDetailByIdResBean.getResponseCode() == 0 && getDetailByIdResBean.getRtnCode_() == 0 && !ear.ˏ) {
                List ˏ = getDetailByIdResBean.ˏ();
                if (ˏ != null && ˏ.size() > 0) {
                    GetDetailByIdResBean$DetailInfoBean getDetailByIdResBean$DetailInfoBean = (GetDetailByIdResBean$DetailInfoBean) ˏ.get(0);
                    if (getDetailByIdResBean$DetailInfoBean != null) {
                        ear.ˋ(this.ॱ, this.ˏ);
                        BaseDistCardBean baseDistCardBean = new BaseDistCardBean();
                        baseDistCardBean.ˏॱ(getDetailByIdResBean$DetailInfoBean.ॱॱ());
                        baseDistCardBean.ˋ(getDetailByIdResBean$DetailInfoBean.ˊॱ());
                        baseDistCardBean.ˏˎ(getDetailByIdResBean$DetailInfoBean.ʻ());
                        baseDistCardBean.ˉ(getDetailByIdResBean$DetailInfoBean.ॱˊ());
                        baseDistCardBean.ॱ(Long.parseLong(getDetailByIdResBean$DetailInfoBean.ʽ()));
                        baseDistCardBean.ॱᐝ(getDetailByIdResBean$DetailInfoBean.ˏॱ());
                        baseDistCardBean.ˋॱ(getDetailByIdResBean$DetailInfoBean.ˋॱ());
                        baseDistCardBean.ˊॱ(getDetailByIdResBean$DetailInfoBean.ᐝॱ());
                        baseDistCardBean.ˋᐝ(getDetailByIdResBean$DetailInfoBean.ᐝ());
                        baseDistCardBean.ॱ(getDetailByIdResBean$DetailInfoBean.ͺ());
                        baseDistCardBean.ˎ(getDetailByIdResBean$DetailInfoBean.ˎ());
                        baseDistCardBean.ॱ(getDetailByIdResBean$DetailInfoBean.ॱᐝ());
                        baseDistCardBean.ͺ(getDetailByIdResBean$DetailInfoBean.ʻॱ());
                        try {
                            new dkd(this.ˏ).ˋ(new DownloadButton(this.ˏ), baseDistCardBean, cke.ˊˊ);
                        } catch (Exception e) {
                            Logger.e("UseCouponControl", e.toString());
                        }
                    } else {
                        evk.ॱ(this.ˏ.getResources().getString(n.ॱᐧ), 0).ˋ();
                    }
                }
            } else {
                evk.ॱ(this.ˏ.getResources().getString(n.ॱᐧ), 0).ˋ();
            }
            ear.ˎ();
        }
    }

    public static void ˊ(String str, Context context) {
        ˏ();
        b ॱ = ॱ(str);
        if (ॱ == null) {
            Logger.e("UseCouponControl", "useCouponControl jsonStr is empty");
            return;
        }
        Logger.ˎ("UseCouponControl", "appName: " + ॱ.ˎ + " packageName: " + ॱ.ˏ + " hmsPackageName: " + ॱ.ˋ + " minHmsVersionCode: " + ॱ.ˊ + " uri: " + ॱ.ॱ + " minFee: " + ॱ.ॱॱ + " KindId: " + ॱ.ʽ);
        PackageInfo ˏ = dnx.ˏ(ॱ.ˋ, context);
        boolean ˋ = ˋ(ॱ.ॱॱ, ॱ.ʽ);
        if ((ˏ == null || ˏ.versionCode < ॱ.ˊ) && !ˋ) {
            eal.ˊ().ˋ().ॱ(ॱ, context);
        } else {
            ˋ(ॱ.ˎ, ॱ.ˏ, ॱ.ॱ, ॱ.ʻ, context);
        }
    }

    private static void ˏ() {
        if (ˊ == null) {
            ˊ = new d();
        }
    }

    private static b ॱ(String str) {
        RpkInfo rpkInfo = null;
        try {
            JSONObject jSONObject = new JSONObject(str);
            b bVar = new b();
            bVar.ˎ = jSONObject.optString("appName");
            bVar.ˏ = jSONObject.optString("packageName");
            bVar.ˋ = jSONObject.optString("hmsPackageName");
            bVar.ˊ = jSONObject.optInt("minHmsVersionCode");
            bVar.ॱ = jSONObject.optString(RemoteBuoyAction.REMOTE_BUOY_URI);
            bVar.ॱॱ = jSONObject.optInt("minFee");
            bVar.ʽ = jSONObject.optInt("kindId");
            if (jSONObject.has("rpkInfo")) {
                String optString = jSONObject.optString("rpkInfo");
                Logger.ˎ("UseCouponControl", "analyzeCouponJson: " + optString);
                bVar.ʼ = optString;
                rpkInfo = ॱ(optString, bVar.ˏ);
            }
            bVar.ʻ = rpkInfo;
            return bVar;
        } catch (JSONException e) {
            Logger.ˋ("UseCouponControl", "UseCouponControl JSONException!");
            return null;
        }
    }

    public static void ˋ(String str, String str2, String str3, RpkInfo rpkInfo, Context context) {
        if (rpkInfo != null) {
            FastSDKEngine.launchFastAppFromAppGallery(context, rpkInfo);
            ˋ(str2, str3);
        } else if (!TextUtils.isEmpty(str) && !TextUtils.isEmpty(str2)) {
            ˋ(str, str2, str3, context);
            ˋ(str2, str3);
        } else if (!TextUtils.isEmpty(str3) && TextUtils.isEmpty(str) && TextUtils.isEmpty(str2)) {
            ᐝ(str3, context);
            ˋ(str2, str3);
        } else {
            Logger.e("UseCouponControl", "Can't recognize the type of the coupon");
        }
    }

    private static void ˋ(String str, String str2) {
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put(HwAccountConstants.TRUSTCIRCLE_VERIFY_REQUEST_KEY_USERID, UserSession.getInstance().getUserId());
        linkedHashMap.put("package_name", str);
        linkedHashMap.put(RemoteBuoyAction.REMOTE_BUOY_URI, str2);
        dgh.ˋ("action_coupon_use", linkedHashMap);
    }

    private static void ˋ(String str, String str2, String str3, Context context) {
        int ˋ = ((cdg) cdb.ॱ(cdg.class)).ˋ(str2);
        String ॱ;
        if (!erw.ˏ(context, str2)) {
            ॱ = drj.ॱ(str2);
            if (ॱ(str2, ˋ)) {
                ˋ(ॱ, context);
            } else {
                ˊ(str, str2, ॱ, 2, context);
            }
        } else if (ˋ == 3 || ˋ == 4) {
            ॱ = drj.ॱ(str2);
            if (ॱ(str2, ˋ)) {
                ˋ(ॱ, context);
            } else {
                ˊ(str, str2, ॱ, 1, context);
            }
        } else {
            ˊ(context, str2, str, ˋ, str3);
        }
    }

    private static void ˊ(Context context, String str, String str2, int i, String str3) {
        PackageInfo ˏ = dnx.ˏ(str, context);
        ॱ(context);
        if (ˏ != null) {
            List arrayList = new ArrayList();
            List arrayList2 = new ArrayList();
            arrayList.add(ˏ.packageName);
            arrayList2.add(ˏ(ˏ.applicationInfo.sourceDir));
            ((cfg) cdb.ॱ(cfg.class)).checkAppValidate(arrayList, arrayList2, new a(context, str, str2, i, str3));
        }
    }

    private static void ॱ(Context context) {
        djl o_djl = new djl(context);
        ˎ = new WeakReference(o_djl);
        o_djl.setCancelable(true);
        o_djl.ˋ(context.getString(n.ˊߴ));
        o_djl.setCanceledOnTouchOutside(false);
        o_djl.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface dialogInterface) {
                ear.ˏ = true;
            }
        });
        o_djl.ˎ(500);
    }

    private static void ˎ() {
        if (ˎ == null) {
            Logger.e("UseCouponControl", "Loading Dialog WeakReference is null when stop it.");
            return;
        }
        djl o_djl = (djl) ˎ.get();
        if (o_djl == null) {
            Logger.e("UseCouponControl", "Loading Dialog is null when stop it.");
            return;
        }
        o_djl.ˏ();
        if (o_djl.isShowing()) {
            try {
                o_djl.dismiss();
            } catch (IllegalArgumentException e) {
                Logger.e("UseCouponControl", "Loading Dialog IllegalArgumentException");
            }
        }
        ˏ = false;
    }

    private static void ˊ(String str, String str2, String str3, int i, Context context) {
        cku ˏ;
        if (i == 1) {
            ˏ = cku.ˏ(context, cku.class, null, context.getResources().getString(n.ॱﾞ));
            ˏ.ॱ(-1, context.getString(n.ॱꜞ));
            ˏ.ˎ(context);
            ˏ.ॱ(-2, context.getString(n.ॱꞌ));
            ˊ(ˏ, context, str3);
        } else if (i == 2) {
            ˏ = cku.ˏ(context, cku.class, context.getResources().getString(n.ॱꓸ), context.getResources().getString(n.ॱㆍ, new Object[]{str}));
            ˏ.ॱ(-1, context.getString(n.ॱꜟ));
            ˏ.ˎ(context);
            ˏ.ॱ(-2, context.getString(n.ॱꞌ));
            ˊ(ˏ, context, str3);
        } else if (i == 3) {
            ˏ = cku.ˏ(context, cku.class, context.getResources().getString(n.ॱꓸ), context.getResources().getString(n.ॱᐨ, new Object[]{str}));
            ˏ.ॱ(-1, context.getString(n.ॱꜟ));
            ˏ.ˎ(context);
            ˏ.ॱ(-2, context.getString(n.ॱꞌ));
            ˏ(ˏ, str2, context, str3);
        }
    }

    private static void ˊ(cku o_cku, final Context context, final String str) {
        o_cku.ॱ(new cks() {
            public void enableNetworking() {
                ear.ˋ(str, context);
            }

            public void upgrade() {
            }

            public void ˋ() {
            }
        });
    }

    private static void ˏ(cku o_cku, final String str, final Context context, final String str2) {
        o_cku.ॱ(new cks() {
            public void enableNetworking() {
                ear.ॱ(context);
                cfw.ˎ(new eaj(str), new e(context, str2));
            }

            public void upgrade() {
            }

            public void ˋ() {
            }
        });
    }

    private static void ˎ(String str, Context context, String str2) {
        if (!TextUtils.isEmpty(str)) {
            BaseCardBean baseCardBean = new BaseCardBean();
            baseCardBean.ॱ(str);
            if (!cii.ˊ().ˊ(context, baseCardBean)) {
                ˏ(str, context, str2);
            }
        }
    }

    private static void ˎ(String str, Context context) {
        ˎ(str, context, "");
    }

    private static void ˏ(String str, Context context, String str2) {
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        Request request = new Request(str, null);
        request.ʼ(str2);
        appDetailActivityProtocol.ˏ(request);
        cjk.ˎ().ˋ(context, new cjm("appdetail.activity", appDetailActivityProtocol));
    }

    private static void ˋ(String str, Context context) {
        ˏ(str, context, "");
    }

    private static void ᐝ(String str, Context context) {
        ˎ(str, context, context.getResources().getString(n.ॱᶥ));
    }

    private static boolean ॱ(String str, int i) {
        for (SessionDownloadTask ˊˊ : dvt.ˏ().ͺ()) {
            if (str.equals(ˊˊ.ˊˊ())) {
                return true;
            }
        }
        if (i == 11 || i == 10) {
            return true;
        }
        return false;
    }

    private static boolean ˋ(int i, int i2) {
        return i == 0 && i2 == 2;
    }

    public static RpkInfo ॱ(String str, String str2) {
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            return null;
        }
        try {
            RpkInfo rpkInfo;
            if (new JSONObject(str).length() > 0) {
                rpkInfo = new RpkInfo();
                rpkInfo.setPackageName(str2);
            } else {
                rpkInfo = null;
            }
            return rpkInfo;
        } catch (JSONException e) {
            Logger.ˋ("UseCouponControl", "rpkInfoJSONException" + e.toString());
            return null;
        }
    }

    private static String ˏ(String str) {
        File file = new File(str);
        if (file.exists()) {
            byte[] ॱ = ॱ(file);
            StringBuilder stringBuilder = new StringBuilder();
            try {
                MessageDigest instance = MessageDigest.getInstance(AaidIdConstant.SIGNATURE_SHA256);
                instance.update(ॱ);
                for (byte b : instance.digest()) {
                    String toHexString = Integer.toHexString(b & 255);
                    if (toHexString.length() < 2) {
                        stringBuilder.append("0");
                    }
                    stringBuilder.append(toHexString);
                }
                return stringBuilder.toString();
            } catch (NoSuchAlgorithmException e) {
                Logger.ˋ("UseCouponControl", "Get sha256 failed: NoSuchAlgorithmException");
                return "";
            }
        }
        Logger.ˋ("UseCouponControl", "Get sha256 failed. Apk not exists!");
        return null;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private static byte[] ॱ(java.io.File r8) {
        /*
        r0 = 0;
        r6 = 0;
        r1 = new java.io.ByteArrayOutputStream;
        r1.<init>();
        r2 = 1024; // 0x400 float:1.435E-42 double:5.06E-321;
        r3 = new byte[r2];
        r2 = new java.util.zip.ZipFile;	 Catch:{ IOException -> 0x006a, all -> 0x004e }
        r2.<init>(r8);	 Catch:{ IOException -> 0x006a, all -> 0x004e }
        r4 = "META-INF/MANIFEST.MF";
        r4 = r2.getEntry(r4);	 Catch:{ IOException -> 0x0029, all -> 0x005a }
        if (r4 == 0) goto L_0x0047;
    L_0x0018:
        r0 = r2.getInputStream(r4);	 Catch:{ IOException -> 0x0029, all -> 0x005a }
        if (r0 == 0) goto L_0x0047;
    L_0x001e:
        r4 = r0.read(r3);	 Catch:{ IOException -> 0x0029, all -> 0x005f }
        if (r4 <= 0) goto L_0x003b;
    L_0x0024:
        r5 = 0;
        r1.write(r3, r5, r4);	 Catch:{ IOException -> 0x0029, all -> 0x005f }
        goto L_0x001e;
    L_0x0029:
        r1 = move-exception;
        r1 = r2;
    L_0x002b:
        r2 = "UseCouponControl";
        r3 = "get manifest file failed due to IOException";
        o.dna.ˋ(r2, r3);	 Catch:{ all -> 0x0064 }
        o.dnw.ˎ(r0);
        o.dnw.ˎ(r1);
    L_0x0038:
        r0 = new byte[r6];
    L_0x003a:
        return r0;
    L_0x003b:
        r1 = r1.toByteArray();	 Catch:{ IOException -> 0x0029, all -> 0x005f }
        o.dnw.ˎ(r0);
        o.dnw.ˎ(r2);
        r0 = r1;
        goto L_0x003a;
    L_0x0047:
        o.dnw.ˎ(r0);
        o.dnw.ˎ(r2);
        goto L_0x0038;
    L_0x004e:
        r1 = move-exception;
        r2 = r0;
        r7 = r0;
        r0 = r1;
        r1 = r7;
    L_0x0053:
        o.dnw.ˎ(r1);
        o.dnw.ˎ(r2);
        throw r0;
    L_0x005a:
        r1 = move-exception;
        r7 = r1;
        r1 = r0;
        r0 = r7;
        goto L_0x0053;
    L_0x005f:
        r1 = move-exception;
        r7 = r1;
        r1 = r0;
        r0 = r7;
        goto L_0x0053;
    L_0x0064:
        r2 = move-exception;
        r7 = r2;
        r2 = r1;
        r1 = r0;
        r0 = r7;
        goto L_0x0053;
    L_0x006a:
        r1 = move-exception;
        r1 = r0;
        goto L_0x002b;
        */
        throw new UnsupportedOperationException("Method not decompiled: o.ear.ॱ(java.io.File):byte[]");
    }
}
